import 'package:flutter_axrjc/datasource/network/api/LightApi.dart';
import 'package:flutter_axrjc/datasource/network/bean/GuideBean.dart';
import 'package:flutter_axrjc/datasource/network/bean/LightBean.dart';
import 'package:flutter_axrjc/datasource/network/request/exp.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

import 'state.dart';

class CheckGuideLogic extends GetxController {
  final CheckGuideState state = CheckGuideState();

  LightBean? lightBean;
  @override
  void onInit() {
    super.onInit();
    lightBean = Get.arguments as LightBean?;
    getCheckGuide();
  }

  Future<void> getCheckGuide() async {
    try {
      GuideBean? bean = await LightApi.getCheckGuide();
      state.guidHtml.value = bean?.configValue ?? '';
      final lightBean = this.lightBean;
      if (lightBean != null) {
        state.video.value = await LightApi.getVideo(
            lampBrandCode: "${lightBean.fixtureBrand}",
            lampTypeId: "${lightBean.fixtureModel}");
      }
    } on ApiException catch (e) {
      EasyLoading.showToast(e.message);
    } catch (e) {
      print(e);
    }
  }
}
